// import { combineReducers } from '@reduxjs/toolkit'
// import counterReducer from './modules/counter/slice'
// import userReducer from './modules/user/slice'

// const rootReducer = combineReducers({
//   counter: counterReducer,
//   user: userReducer,
// })

// export default rootReducer
import { combineReducers } from '@reduxjs/toolkit'
// import thunk from 'redux-thunk' // 异步数据管理
// import logger from 'redux-logger' // 让 redux 调试更优秀
// 批量导入 ./modules 下所有 slice.ts 文件
const modules = import.meta.glob('./modules/*/slice.js', { eager: true })

const reducers = Object.keys(modules).reduce((acc, path) => {
  // 从路径中提取文件夹名称作为键，例如 './modules/counter/slice.ts' -> 'counter'
  const key = path.split('/')[2]
  // 获取默认导出的 reducer
  const reducer = modules[path].default
  acc[key] = reducer
  return acc
}, {})

const rootReducer = combineReducers(reducers)

export default rootReducer
